<template>
  <d2-container>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <div class="d2-breadcrumb">
        <el-breadcrumb-item>系统管理</el-breadcrumb-item>
        <el-breadcrumb-item>新增账号</el-breadcrumb-item>
      </div>
    </el-breadcrumb>
    <el-form label-width="100px" :model="query" :rules="rules" ref="add">
      <el-form-item label="账号" prop="user">
        <el-input v-model="query.user" style="width: 240px;"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="psw">
        <el-input v-model="query.psw" style="width: 240px;" type="passwprd"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="add">保存</el-button>
      </el-form-item>
    </el-form>
  </d2-container>
</template>
<script>
export default {
  name: "Add-Role",
  data() {
    return {
      query: {
        user: null,
        psw: null,
      },
      rules: {
        name: [
          { required: true, message: "账号不能为空", trigger: "blur" }
        ],
        abbr: [{ required: true, message: "密码不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    add() {
      this.$refs["add"].validate(valid => {
        if (valid) {
          let params = {
            ...this.query
          };
          this.$axios.post("/admin/addAdmin", params).then(result => {
            if (!result) {
              this.$message.success("操作成功");
              this.$router.push("/admin");
              this.$refs["add"].resetFields();
            } else {
              this.$message.error(result.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    },
  },
 
};
</script>